<?php
$q = $_GET["q"];

$host = "localhost";
$user = "root";
$pass = "";
$db = "scrum";
	
//Testar att ansluta mot databasen
$con = mysql_connect($host, $user, $pass);
	
if(!$con)
{
	die('Kunde inte ansluta: ' . mysql_error());
}
		
mysql_select_db($db, $con);

if(strlen($q) > 0)
{
	$sql = "SELECT highscore, namn, email FROM highscore WHERE namn LIKE '" . $q . "%' OR email LIKE '" . $q . "%' 
			OR namn LIKE '%" . $q . "%' OR email LIKE '%" . $q . "%' ORDER BY highscore DESC LIMIT 10";
	$result = mysql_query($sql);

	echo "
		<table>
			<tr bgcolor='#CCC49F'>
				<td>Highscore</td>
				<td>Namn</td>
				<td>Email</td>
			<tr>";
	$temp = 0;
	
	while($row = mysql_fetch_array($result))
	{
		$color = "";
		if($temp % 2)
		{
			//Ojämnt
			$color = "#EADCAE";
		}
		else
		{
			//Jämn
			$color = "#ADB96E";
		}
		
		echo "<tr bgcolor='" . $color . "'>
			<td>" . $row['highscore'] . "</td>
			<td>" . $row['namn'] . "</td>
			<td>" . $row['email'] . "</td>
			</tr>";
			
		$temp++;
	}
	echo "</table>";
}

mysql_close($con);
?>